#! /bin/sh
# Suhrot - Demo shell script for SUHROT
# Author: Nils Maercklin, GFZ Potsdam, Germany, 2001 

# PostScript flag (set to 1 to generate PS output instead of X display):
POSTSCRIPT=0

# X window sizes and positions:
WIDTH=400
HEIGHT=600
WIDTHOFF1=0
WIDTHOFF2=410
HEIGHTOFF=50


# Create a three-component file:

echo "Create three-component file with energy only one horizontal component"

sunull nt=64 ntr=36 |
sushw key=trid,tracf a=12,1 b=0,1 > temp.su

suplane npl=1 len1=36 ntr=36 ct1=16 |
subfilt zerophase=0 |
sushw key=trid,tracf a=13,1 b=0,1 >> temp.su

sunull nt=64 ntr=36 |
sushw key=trid,tracf a=45,1 b=0,1 >> temp.su


# Sort by key header word tracf:

echo "Sorting traces"
susort tracf trid <temp.su >indata.su 


# Rotating traces by angles from 0 to 350 deg:

echo "Rotating traces"
suhrot <indata.su > rotated.su a=0,350 x=1,36 angle=deg

### Use this to read rotation angles from files:
#
# echo "1 36"  | tr " " "\n" >x.asc  # ASCII file of x
# echo "0 350" | tr " " "\n" >a.asc  # ASCII file of a
# a2b <x.asc > x.bin n1=1            # binary file of x
# a2b <a.asc > a.bin n1=1            # binary file of a
#
# suhrot <indata.su > rotated.su afile=a.bin xfile=x.bin n=2 angle=deg
#
###


# X display of result:

if [ $POSTSCRIPT -eq 0 ]
then

  echo "X display of results"
  
  # Display 1st horizontal component:
  
  suwind < indata.su key=trid min=13 max=13 |
  suxwigb title="horizontal component H1" windowtitle="H 1" \
    label1="Time(SEC)" label2="Trace number" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF &

  suwind < rotated.su key=trid min=15 max=15 |
  suxwigb title="rotated data of H1" windowtitle="rotated H 1" \
    label1="Time(SEC)" label2="Angle(DEG)" d2=10 f2=0 \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF &
exit 0

# PostScript plot of results:
else

  echo "PostScript plot of result"

  # Plot input data (one horizontal component):
  suwind <indata.su key=trid min=13 max=13 |
  supswigp linewidth=0 title="horizontal component H1" \
    label1="Time(SEC)" label2="Trace number" > plot1.eps

  # Plot rotated data of the same component:
  suwind <rotated.su key=trid min=13 max=13 |
  supswigp linewidth=0 title="rotated data of H1" \
    label1="Time(SEC)" label2="Angle(DEG)" d2=10 f2=0 > plot2.eps
  
  # merge two plots onto one page:
  merge2 plot1.eps plot2.eps > suhrot.eps
  
  echo "Output PostScript file: suhrot.eps"
  echo " "
  echo "You may view this with your PostScript previewer"
fi

exit 0
